cmake_minimum_required(VERSION 3.5)

project(Cute-CPP VERSION 0.1 LANGUAGES CXX)

set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

#set(CMAKE_PARALLEL_LEVEL 6)
#set(CMAKE_EXE_LINKER_FLAGS "-j12") #多核编译
#set(CMAKE_EXE_LINKER_FLAGS "-O3 -Wall -static-libgcc -static-libstdc++ -Wl,-Bstatic,--whole-archive -lwinpthread -Wl,--no-whole-archive")#静态编译
#set(CMAKE_EXE_LINKER_FLAGS "-Wl,-Bstatic,--whole-archive -lwinpthread -Wl,--no-whole-archive")#静态编译

find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Widgets PrintSupport Network)
find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Widgets PrintSupport Network)
find_package(Qt6 REQUIRED COMPONENTS LinguistTools)

INCLUDE_DIRECTORIES(${PROJECT_SOURCE_DIR})

#include_directories(E:/libtorch2.4/include) #include路径
#link_directories(E:/Qt/6.7.2/mingw_64/lib) #库的lib或者bin路径

set(PROJECT_SOURCES
	main.cpp
	mainwindow.cpp
	mainwindow.h
)

if(${QT_VERSION_MAJOR} GREATER_EQUAL 6)
    qt_add_executable(Cute-CPP
        MANUAL_FINALIZATION
        ${PROJECT_SOURCES}
        globalvar.h globalvar.cpp
        CompilerSet.h
        stable.h
        manualdialog.h manualdialog.cpp
        editoroptiondialog.h editoroptiondialog.cpp
        astyleoptiondialog.h astyleoptiondialog.cpp
        directorieswidget.h directorieswidget.cpp
        compileoptiondialog.h compileoptiondialog.cpp
        highlighter.h highlighter.cpp
        codeeditor.h codeeditor.cpp
        findreplacedialog.h findreplacedialog.cpp
        appIcon.rc
        resources.qrc
        colorthemedialog.h colorthemedialog.cpp
	profilereditor.h profilereditor.cpp
	newprojectdialog.h newprojectdialog.cpp
	informationdialog.h informationdialog.cpp
	searchresultdelegate.h searchresultdelegate.cpp
	richlinecode.h

    )

    qt_add_translations(Cute-CPP TS_FILES Cute-CPP_zh_CN.ts)

    #Define target properties for Android with Qt 6 as:
    set_property(TARGET Cute-CPP APPEND PROPERTY QT_ANDROID_PACKAGE_SOURCE_DIR
		${CMAKE_CURRENT_SOURCE_DIR}/android)
#For more information, see https://doc.qt.io/qt-6/qt-add-executable.html#target-creation
else()
    if(ANDROID)
	add_library(Cute-CPP SHARED
            ${PROJECT_SOURCES}
        )
        #Define properties for Android with Qt 5 after find_package() calls as:
        set(ANDROID_PACKAGE_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/android")
    else()
	add_executable(Cute-CPP
            ${PROJECT_SOURCES}
        )
    endif()
endif()

target_link_libraries(Cute-CPP
    PRIVATE Qt${QT_VERSION_MAJOR}::Widgets
    PRIVATE Qt${QT_VERSION_MAJOR}::PrintSupport
    PRIVATE Qt${QT_VERSION_MAJOR}::Network
    #PRIVATE Qt6PrintSupport.a
    #PRIVATE Qt6Network.a
)

target_precompile_headers(Cute-CPP PUBLIC
    "stable.h"
)

# Qt for iOS sets MACOSX_BUNDLE_GUI_IDENTIFIER automatically since Qt 6.1.
# If you are developing for iOS or macOS you should consider setting an
# explicit, fixed bundle identifier manually though.
if(${QT_VERSION} VERSION_LESS 6.1.0)
    set(BUNDLE_ID_OPTION MACOSX_BUNDLE_GUI_IDENTIFIER com.example.Cute-CPP)
endif()

set_target_properties(Cute-CPP PROPERTIES
    ${BUNDLE_ID_OPTION}
    MACOSX_BUNDLE_BUNDLE_VERSION ${PROJECT_VERSION}
    MACOSX_BUNDLE_SHORT_VERSION_STRING ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}
    MACOSX_BUNDLE TRUE
    WIN32_EXECUTABLE TRUE
)

include(GNUInstallDirs)
install(TARGETS Cute-CPP
    BUNDLE DESTINATION .
    LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
    RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
)

if(QT_VERSION_MAJOR EQUAL 6)
    qt_finalize_executable(Cute-CPP)
endif()
